package com.sumer.thread;

/**
 * 测试守护线程
 */
public class ThreadDaemon {
    public static void main(String[] args) {
        DaemonThread daemonThread = new DaemonThread();
        Thread thread = new Thread(daemonThread);
        thread.setDaemon(true);
        thread.start();
        UserThread userThread = new UserThread();
        new Thread(userThread).start();
    }
}

/**
 * 守护线程
 */
class DaemonThread implements Runnable{

    @Override
    public void run() {
        while (true){
            System.out.println("守护线程执行中...........");
        }
    }
}


/**
 * 用户线程
 */
class UserThread implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("用户线程执行中" + i);
        }
    }
}
